< previous page page_450 next page >

Page 450
Using the Employees Class
In the sample form, youll see a declaration of the Employees class in the General Declarations area:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim moEmps As Employees
In the Form_Load() event, you need to create a new instance of this Employees class:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub Form_Load()
   txtEmpID = 1
   txtFirst = "Bill"
   txtLast = "Gates"
   txtSalary = 1000000

   Set moEmps = New Employees
End Sub
Next, look in the Add command buttons Click event to see how to use this Employees collection class:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdAdd_Click()
   ' Add information to the Employees class
   moEmps.Add EmpID:=CLng(txtEmpID), _
              FirstName:=txtFirst, _
              Salary:=CCur(txtSalary), _
              LastName:=txtLast

End Sub
This code uses the module-level Employees object to add the information from the form into the class. In this example, the Add method is called using the named arguments to make it clear which values are being passed.
Next, you can retrieve a particular Employee object by filling a value into the txtSearch text box and clicking the Display command button:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdDisplay_Click()
   Dim oEmp As Employee

   If moEmps.Count > 0 Then
      ' Retrieve Search Criteria from Collection
      Set oEmp = moEmps.Item(txtSearch)

 
< previous page page_450 next page >

If you like this book, buy it!